﻿@using SDAU.GCT.OA.Model
@model IEnumerable<SDAU.GCT.OA.Model.UserInfo>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>SetRole</title>
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script type="text/javascript">
        function afterSetRole(data) {
            if (data == "ok") {
                window.parent.window.afterSetRole();
            }
        }

        function submitForm() {
            $("form").submit();
        }
    </script>
</head>
<body>
    <div>
        <h2>当前给用户：  @ViewBag.Uname 设置角色</h2>
        <hr />
        @{
            //所有的角色
            List<RoleInfo> allRoles = ViewBag.AllRoles;
            //所有当前用户已经存在的角色
            List<int> existRoleIdList = ViewBag.ExitsRoles;     
            using (Ajax.BeginForm("ProcessSetRole", "UserInfo", new AjaxOptions() { OnSuccess = "afterSetRole" }))
            {

                <input type="hidden" name="UId" value="@ViewBag.Id" />

                int i = 0;
                foreach (var roleInfo in allRoles)
                {
                    string str = "ckb_" + roleInfo.Id;
                    if (i % 3 == 0 && i != 0)
                    {
                        <hr />
                    }
                    if (existRoleIdList.Contains(roleInfo.Id))
                    {
                        <input type="checkbox" checked="checked" value="@str" name="@str" id="@str" />
                   }
                    else
                    {
                        <input type="checkbox" value="@str" name="@str" id="@str" />
                    }

                    <label for="@str">@roleInfo.RoleName</label>

                    i++;

                }
            }
        }
    </div>
</body>
</html>